﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StockView.aspx.cs" Inherits="Manageweb_Stock_StockView" MasterPageFile="~/Manageweb/MemberMaster.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <title>股票走势</title>
    <link rel="Stylesheet" href="../images/css.css" />
    <link href="../Css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .grid
        {
            margin: 0 auto;
        }
        #memberstocklist div
        {
            border: 0px;
            margin: 0;
            padding: 0;
        }
        .usual
        {
            background: #fff;
            color: #111;
           
            width: 320px;
            margin: 0px auto;
        }
        .IID
        {
            display: none;
        }
    </style>

    <script src="../Jquery/jquery.min.js" type="text/javascript"></script>

    <script src="../Jquery/highcharts.js" type="text/javascript"></script>

    <script src="../Jquery/exporting.js" type="text/javascript"></script>

    <script src="../Jquery/jquery.idTabs.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        var chart;

        function createChart(xcategories, ycategories, dataName) {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    defaultSeriesType: 'line',
                    marginRight: 110,
                    marginBottom: 60,
                    width: 700,
                    height: 180
                },
                title: {
                    text: '平均价格'
                },
                xAxis: {
                    categories: xcategories,
                    labels: {
                        rotation: -45,
                        align: 'right',
                        style: { font: 'normal 11px Verdana,sans-serif' }
                    }

                },
                yAxis: {
                    title: { text: '平均价格' }
                },
                tooltip: {
                    formatter: function() {
                        return '<b>' + this.series.name + '</b><br/>' +
								this.x + ': ' + this.y + '元';
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -4,
                    y: 50,
                    borderWidth: 1
                },
                series: [{
                    name: dataName,
                    data: ycategories
}]

                });

            }

            $(function() {

                var xcategories;
                var ycategories;
                var dataName;
                var selectedcode;

                var gvClientID = '<%=GV_StockInfoList.ClientID%>';

                //准备数据
                function DrawChart() {

                    $.getJSON("../../Ajax.aspx", { stockcode: selectedcode }, function(json) {
                        if (json[0].isSuccess == "0") { alert('没有相应的数据'); return; }
                        dataName = json[0].stockname;
                        xcategories = json[0].xdata;
                        createChart(xcategories, json[0].ydata, dataName);
                    });


                }
                //为标签A绑定事件
                $('a[name="operate"]').click(function() {
                    var stockcode = $(this).parents('tr').children('td:eq(1)').html();
                    selectedcode = stockcode;
                    DrawChart();
                });

                function begin() {
                    selectedcode = $('#' + gvClientID).find('tr:eq(1)').children('td:eq(1)').html();
                    DrawChart();
                    setInterval(DrawChart, 30000);
                }
                //Main()
                begin();
                GMInit();

            });
            var memStockList;
            var boardID;
            var txtStockCode;
            var txtStockName;
            var txtStockPrice;
            var txtStockCount;
            var txtCost;
            var hidMemStockCode;
            var btnBindMemStock;
            var JYType;
            var memCode;
            var recordID;
            function GMInit() {
                boardID = '<%=this.GV_StockInfoList.ClientID %>';

                txtStockCode = '<%=txtStockCode.ClientID %>';
                txtStockName = '<%=txtStockName.ClientID %>';
                txtStockPrice = '<%=txtPrice.ClientID %>';

                txtStockCount = '<%=txtCount.ClientID %>';
                txtCost = '<%=txtCost.ClientID %>';
                hidMemStockCode = '<%=hidMemStockCode.ClientID %>';
                btnBindMemStock = '<%=btnBindMemStock.ClientID %>';
                memStockList = '<%=GV_MemStock.ClientID %>';

                JYType = '<%=hidJYType.ClientID %>';
                memCode = '<%=hidMemID.ClientID %>';
                recordID = '<%=hidRecordID.ClientID %>';

                $('#' + txtStockCount).keypress(function() {
                    return event.keyCode >= 48 && event.keyCode <= 57;

                });

                $('#' + txtStockCount).keyup(function() {

                    var countValue = $(this).val();

                    if (countValue == '') {
                        return;
                    }

                    var regex = /^[0-9]*[1-9][0-9]*$/i;

                    if (!regex.test(countValue)) {

                        return;
                    }

                    var price = parseFloat($('#' + txtStockPrice).val());
                    var count = parseInt($('#' + txtStockCount).val());
                    $('#' + txtCost).val(price * count);

                });


                $('a[name="buy"]').click(function() {

                    var tds = $(this).parents('tr').children('td');

                    $('#' + txtStockCode).val(tds[1].innerHTML);
                    $('#' + txtStockName).val(tds[0].innerHTML);
                    $('#' + txtStockPrice).val(tds[2].innerHTML);
                    $('#' + hidMemStockCode).val(tds[1].innerHTML);
                    $('#' + btnBindMemStock).click();
                    $('#' + txtCost).val("");
                    $('#' + txtStockCount).val("");

                    $('#' + JYType).val("dapan");
                });
            }
            function test() {


                $('#' + txtStockCode).val(arguments[1]);
                $('#' + txtStockName).val(arguments[0]);
                $('#' + txtStockPrice).val(arguments[2]);
                $('#' + memCode).val(arguments[4]);
                $('#' + recordID).val(arguments[5]);
                alert(arguments[5]);
                $('#' + txtCost).val("");
                $('#' + txtStockCount).val("");
                $('#' + JYType).val("member");

            }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
     <div style="width: 725px; text-align: center; margin: 0 auto;">
        <div id="container" style="width: 720; margin-top: 2px;   border: 1px solid gray;">
        </div>
        <div id="fenge" style="width: 720; margin-top: 2px; font-size:12px;  ">
            走势图
        </div>
    <%--    <asp:UpdatePanel runat="server" ID="updatepanel">
            <ContentTemplate>--%>
                <asp:GridView ID="GV_StockInfoList" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" CellPadding="2" 
            DataKeyNames="StockCode" ForeColor="#333333"
                    Width="720px" EmptyDataText="暂无数据" PageSize="4" 
            onpageindexchanging="GV_StockInfoList_PageIndexChanging">
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#EFF3FB" />
                    <Columns>
                        <asp:BoundField DataField="StockName" HeaderText="名称" />
                        <asp:BoundField DataField="StockCode" HeaderText="编号" InsertVisible="False" ReadOnly="True" />
                        <asp:BoundField DataField="CMoney" HeaderText="最新价(元)" DataFormatString="{0:N2}" />
                        <asp:BoundField DataField="count" HeaderText="数量" />
                        <asp:BoundField DataField="updatetime" HeaderText="日期" />
                        <asp:TemplateField HeaderText="走势图">
                            <ItemTemplate>
                                <a href="#" name="operate">
                                    <img alt="走势图" style="border: 0; margin: 0;" height="18" src="../images/chart.png" /></a>
                            </ItemTemplate>
                        </asp:TemplateField>
                       <%-- <asp:TemplateField HeaderText="购买">
                            <ItemTemplate>
                                <a href="#" name="buy">买入</a>
                            </ItemTemplate>
                        </asp:TemplateField>--%>
                    </Columns>
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
       <%--     </ContentTemplate>
        </asp:UpdatePanel>--%>
    </div>
    
        <table style="margin: 0 auto;  display:none;">
        <tr>
            <td>
                <div id="usual1" class="usual">
                    <ul>
                        <li><a style="font-size: 13px;" href="#tab1">股票购买</a> </li>
                    </ul>
                    <div id="tab1">
                        <table width="100%">
                            <tr>
                                <td style="width: 78px">
                                    股票代码
                                </td>
                                <td>
                                    <asp:TextBox ID="txtStockCode" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    股票名称
                                </td>
                                <td>
                                    <asp:TextBox ID="txtStockName" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买价格
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPrice" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买数量(股)
                                </td>
                                <td>
                                    <asp:TextBox ID="txtCount" runat="server" onpaste="return false;" ondragenter="return false;"
                                        Width="80px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                                        ControlToValidate="txtCount" Display="Dynamic" SetFocusOnError="True" ValidationGroup="purchase"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="必须为正整数"
                                        SetFocusOnError="True" ControlToValidate="txtCount" Display="Dynamic" ValidationExpression="^[0-9]*[1-9][0-9]*$"
                                        ValidationGroup="purchase"></asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    购买金额(元)
                                </td>
                                <td>
                                    <asp:TextBox ID="txtCost" runat="server" ReadOnly="True" Width="80px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <asp:Button ID="btnOK" runat="server" Text="确认购买" OnClick="btnOK_Click" ValidationGroup="purchase" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                </td>
                            </tr>
                        </table>
                        <asp:Label ID="lblMsg" runat="server"></asp:Label>
                    </div>
                </div>
            </td>
            <td style="vertical-align: top;">
                <div id="memberstock" class="usual">
                    <ul>
                        <li><a style="font-size: 13px;" href="#tab1">会员股票</a> </li>
                    </ul>
                    <div id="memberstocklist">
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <asp:GridView ID="GV_MemStock" runat="server" AutoGenerateColumns="False" Width="300px"
                                    EmptyDataText="没有会员卖出该股票" OnRowDataBound="GV_MemStock_RowDataBound">
                                    <Columns>
                                        <asp:BoundField DataField="stockname" HeaderText="名称" />
                                        <asp:BoundField DataField="stockcode" HeaderText="代码" />
                                        <asp:BoundField DataField="cmoney" HeaderText="价格" />
                                        <asp:BoundField DataField="count" HeaderText="数量" />
                                        <asp:BoundField DataField="userid" HeaderText="会员" />
                                        <asp:BoundField DataField="iid" HeaderText="id">
                                            <ItemStyle CssClass="IID" />
                                        </asp:BoundField>
                                    </Columns>
                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                </asp:GridView>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnBindMemStock" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </div>
                </div>
            </td>
        </tr>
    </table>

    <script type="text/javascript">        $("#usual1 ul").idTabs(); </script>

    <asp:Button ID="btnBindMemStock" runat="server" Height="20px" OnClick="btnBindMemStock_Click"
        CssClass="IID" Text="Button" />
    <asp:HiddenField ID="hidMemStockCode" runat="server" />
    <asp:HiddenField ID="hidJYType" runat="server" />
    <asp:HiddenField ID="hidMemID" runat="server" />
    <br />
    <asp:HiddenField ID="hidRecordID" runat="server" />
</asp:Content>
 